package com.fxu.tpl.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fxu.framework.core.base.Cascade;
import com.fxu.framework.core.enums.EnumValid;
import com.fxu.framework.core.enums.StatusEnum;
import com.fxu.framework.core.sql.SEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.constraints.NotNull;
import java.io.Serializable;
import java.util.Date;

import static com.baomidou.mybatisplus.annotation.FieldFill.UPDATE;

/***
 * <p>fxu</p>
 * 一对多表：[link]的数据实体类
 * @author fangxu
 * @version 2019-09-23
 ***/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(value = "Link", description = "一对多")
@TableName("fxu_link")
public class Link extends SEntity<Link> implements Serializable {
/*=== 自动生成代码 开始 ===*/
    private static final long serialVersionUID = -2577382426660298656L;

    @TableId(type = IdType.AUTO)
    @ApiModelProperty(value = "自增ID")
    private Long id;

    @ApiModelProperty(value = "表ID", required = true)
    @NotNull(message = "表ID必须赋值")
    private Long tableId;

    @ApiModelProperty(value = "连接表ID", required = true)
    @NotNull(message = "连接表ID必须赋值")
    private Long linkTableId;

    @ApiModelProperty(value = "连接字段ID", required = true)
    @NotNull(message = "连接字段ID必须赋值")
    private Long linkColumnId;

    @ApiModelProperty(value = "关联表并保存", required = true)
    @NotNull(message = "关联表并保存必须赋值")
    private Boolean linkSave;

    @ApiModelProperty(value = "是否列表显示", required = true)
    @NotNull(message = "是否列表显示必须赋值")
    private Boolean listShow;

    @ApiModelProperty(value = "是否一对多")
    private Boolean isList;

    @ApiModelProperty(value = "创建时间")
    private Date createTime;

    @ApiModelProperty(value = "修改时间")
    private Date updateTime;

    @ApiModelProperty(value = "状态[1:正常,0:删除]")
    @EnumValid(target = StatusEnum.class, message = "状态的值必须为{1:正常,0:删除}")
    private Integer status;

    @TableField(fill = UPDATE, update = "%s+1")
    @ApiModelProperty(value = "版本号")
    private Integer version;

    @TableField(exist = false)
    @ApiModelProperty(value = "表对象")
    @Cascade(thisField = "tableId", linkField = "id")
    private Table table;

    @TableField(exist = false)
    @ApiModelProperty(value = "连接表对象")
    @Cascade(thisField = "linkTableId", linkField = "id")
    private Table linkTable;

    @TableField(exist = false)
    @ApiModelProperty(value = "连接字段对象")
    @Cascade(thisField = "linkColumnId", linkField = "id")
    private Column linkColumn;

    // 获得状态的说明
    public String getStatusText() {
        return StatusEnum.desc(status);
    }
/*=== 自动生成代码 结束 ===*/
}
